package com.lagou.homework02;

import java.util.*;

public class WorkerTest {
    public static void main(String[] args) {
        //创建一个List集合，并添加三个员工
        List lst = new LinkedList();
        lst.add(new Worker("凤姐",35,5000));
        lst.add(new Worker("欧阳峰",60,8000));
        lst.add(new Worker("刘德华",40,30000));
        System.out.println("lst =" + lst);
        System.out.println("-------------------------------------------------");
        //在"欧阳峰"之前插入一个员工，信息为：姓名："张柏芝"，年龄：35，工资3300
        lst.add(lst.indexOf(new Worker("欧阳峰",60,8000)),new Worker("张柏芝",35,3300));
        System.out.println("lst =" + lst);
        System.out.println("-------------------------------------------------");
        //删除"刘德华"的信息
        lst.remove(new Worker("刘德华",40,30000));
        System.out.println("lst =" + lst);
        System.out.println("-------------------------------------------------");
        //利用for 循环遍历，打印List 中所有员工的信息
        for (Object obj : lst) {
            System.out.println("取出来的元素是：" + obj);
        }
        System.out.println("-------------------------------------------------");
        //利用迭代遍历，对List 中所有的员工调用work方法
        Iterator iterator = lst.iterator();
        while (iterator.hasNext()) {
            Worker w1 = (Worker) iterator.next();
            w1.work();
        }
        System.out.println("-------------------------------------------------");
        //当姓名，年龄，工资全部相等时返回true
        Worker w1 = new Worker("张飞",40,4000);
        Worker w2 = new Worker("张飞",40,4000);
        Worker w3 = new Worker("关羽",40,4000);
        Worker w4 = new Worker("张飞",50,4000);
        Worker w5 = new Worker("张飞",40,6000);
        System.out.println(w1.equals(w2));
        System.out.println(w1.equals(w3));
        System.out.println(w1.equals(w4));
        System.out.println(w1.equals(w5));


    }
}
